package com.hongshan.wallet.core.wallet

import android.arch.lifecycle.ViewModelProviders
import android.databinding.ObservableField
import android.databinding.ViewDataBinding
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.hongshan.wallet.BR
import com.hongshan.wallet.MyApplication
import com.hongshan.wallet.R
import com.hongshan.wallet.base.BaseOnPropertyChangedCallback
import com.hongshan.wallet.base.MyFragment
import com.hongshan.wallet.bean.UserDescBean

/**
 * Copyright Qiandai Ltd.
 * Copyright (c) 2019
 * All rights reserved
 *
 * @project  : Wallet
 * @package  : com.example.wallet.core.wallet
 * @author   : Administrator
 * @data     : 2019/3/19
 * @email    : zhangxx@baihang-china.com
 */
class WalletFragment : MyFragment<ViewDataBinding, WalletViewModel>() {

    val vm by lazy { ViewModelProviders.of(this)[WalletViewModel::class.java] }

    override fun initVariableId() = BR.walletVm

    override fun initContentView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?) =
        R.layout.fragment_wallet

    override fun initViewModel() = vm

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        MyApplication.userInfo.addOnPropertyChangedCallback(BaseOnPropertyChangedCallback<ObservableField<UserDescBean>>{ sender, _->
            viewModel.balance.set(sender.get()?.commission_balance)
            viewModel.commision.set("累计佣金 ${MyApplication.userInfo.get()?.cumulative_commission} 元")
        })
    }
}